#!/usr/bin/python3.5

# -*- coding: utf-8 -*-




class Solution:
    def removeDuplicates(self, nums):
        k=0
        cur =1
        while cur  < len(nums):
            if nums[k]!=nums[cur]:
                k+=1
                nums[k]=nums[cur]
                cur+=1
            else:
                cur+=1
        return k+1

    def removeDuplicates_cnt(self, nums):

        cnt = 0
        lens = len(nums)
        for i in range(1,lens):
            replace = i - cnt
            if nums[i]!=nums[replace-1]:
                nums[replace] = nums[i]
            else:
                cnt+=1
        return lens-cnt







if __name__=='__main__':
    # arr=[int(x) for x in input().strip().split(' ')]
    arr=[0,1,1,1,2,2,3,3,4]
    solution=Solution()
    k = solution.removeDuplicates_cnt(arr)
    print(arr[:k])







